<?php
/**
 * (exporter)
 */
namespace App\Exporter\Operation;

use App\Models\Basics\SysCountry;
use App\Models\Basics\Transport;
use App\Models\Operation\ProfitSku;
use App\Util\User;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\WithMapping;
class ProfitTryExporter extends ExcelExporter implements WithMapping
{
    protected $fileName = '公司产品利润率.csv';

    protected $headings = ['国家','销售员','运输方式','产品名称',
                           '汇率','TP1(RMB)','TP1','头程费','FBA费','库存费','其他平台费','commission',
                           '退货费','VAT费','成本','销售价格','毛利','毛利率'];

    public function map($model) : array
    {
        return [
            SysCountry::getCountryById($model->country_id),
            User::getUsernameById($model->seller_id),
            Transport::$_transport[$model->transport],
            $model->sku_cn,
            $model->rate_odds,
            $model->tpl_rmb,
            !$model->rate_odds ? '' : numberFormat(round($model->tpl_rmb / $model->rate_odds,3)),
            $model->head_cost,
            $model->fba_fee,
            round($model->sale_price * ProfitSku::$_inventory / 100 ,3),
            round($model->sale_price * ProfitSku::$_other / 100 ,3),
            $model->commission,
            $model->return,
            $model->vat,
            $model->cost,
            $model->sale_price,
            $model->profit,
            $model->profit_rate];
    }
}
